package com.hxzy.common.util;

import cn.hutool.json.JSONUtil;
import com.hxzy.vo.back.DishFlavorProperty;
import com.hxzy.vo.back.DishFlavorVO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author wy
 * @Description 数据字典工具类
 * @Date 2023/4/15 9:15
 * @Version 1.0
 */
public class CommonDataUtil {

    public static final String SEX="sex";
    public static final String STATUS="status";

    /**
     * 商家审核状态
     */
    public static final String PROCESS="process";

    /**
     * 商品上下架状态
     */
    public static final String PRODUCT_STATUS="product_status";

    /**
     *  口味列表
     */
    public static final String DISH_FLAVOR="dish_flavor";

    /**
     * 性别数据
     * @return
     */
    public static List<Map<String,Object>> genderData(){
        List<Map<String,Object>> arr=new ArrayList<>();
        Map<String,Object>  mp01=new HashMap<>();
        mp01.put("label","男");
        mp01.put("value",1);
        mp01.put("listClass","");

        Map<String,Object>  mp02=new HashMap<>();
        mp02.put("label","女");
        mp02.put("value",0);
        mp02.put("listClass","success");
        arr.add(mp02);
        arr.add(mp01);
        return arr;
    }



    /**
     * 状态（1停用，0正常）
     * @return
     */
    public static List<Map<String,Object>> statusData(){
        List<Map<String,Object>>  arr=new ArrayList<>();
        Map<String,Object>  mp01=new HashMap<>();
        mp01.put("label","停用");
        mp01.put("value",1);
        mp01.put("listClass","danger");

        Map<String,Object>  mp02=new HashMap<>();
        mp02.put("label","正常");
        mp02.put("value",0);
        mp02.put("listClass","");

        arr.add(mp02);
        arr.add(mp01);
        return arr;
    }

    /**
     *  审核状态（审核通过，1未审核,2审核不通过）
     * @return
     */
    public static List<Map<String,Object>> processData(){
        List<Map<String,Object>>  arr=new ArrayList<>();
        Map<String,Object>  mp01=new HashMap<>();
        mp01.put("label","未审核");
        mp01.put("value",1);
        mp01.put("listClass","warning");

        Map<String,Object>  mp02=new HashMap<>();
        mp02.put("label","审核通过");
        mp02.put("value",0);
        mp02.put("listClass","");

        Map<String,Object>  mp03=new HashMap<>();
        mp03.put("label","审核不通过");
        mp03.put("value",2);
        mp03.put("listClass","danger");

        arr.add(mp02);
        arr.add(mp01);
        arr.add(mp03);
        return arr;
    }

    /**
     *  商品上下架状态（ 1：上架 ，0：下架）
     * @return
     */
    public static List<Map<String,Object>> productStatusData(){
        List<Map<String,Object>>  arr=new ArrayList<>();
        Map<String,Object>  mp01=new HashMap<>();
        mp01.put("label","上架");
        mp01.put("value",1);
        mp01.put("listClass","");

        Map<String,Object>  mp02=new HashMap<>();
        mp02.put("label","下架");
        mp02.put("value",0);
        mp02.put("listClass","danger");

        arr.add(mp02);
        arr.add(mp01);
        return arr;
    }

    /**
     *  默认的口味列表
     * @return
     */
    public static List<DishFlavorVO> dishFlavorData(){
        List<DishFlavorVO> arr=new ArrayList<>();

        String[] names={"温度","糖度","辣度"};
        String[] values={
                "[\"正常冰\",\"少冰\",\"常温\",\"温热\"]",
                "[\"正常糖\",\"七分糖\",\"五分糖\"]",
                "[\"不辣\",\"微辣\",\"中辣\",\"麻辣\"]"
        };

        for(int i=0;i<names.length;i++){
            DishFlavorVO vo=new DishFlavorVO();
            vo.setName(names[i]);

            //组装值
            List<DishFlavorProperty> arrProp=new ArrayList<>();
            //得到默认的值，转换成json
            List<String> stringList = JSONUtil.toList(values[i], String.class);
            for(String v : stringList){
                DishFlavorProperty dishFlavorProperty=new DishFlavorProperty();
                dishFlavorProperty.setValue(v);
                dishFlavorProperty.setPrice(0);
                arrProp.add(dishFlavorProperty);
            }
            vo.setValue(arrProp);

            arr.add(vo);
        }

        return arr;
    }


    /**
     * 简单工厂方法
     * @param dictName
     * @return
     */
    public static List findByDictName(String dictName){
        if(dictName.equals(CommonDataUtil.SEX)){
            return genderData();
        }else if(dictName.equals(CommonDataUtil.STATUS)){
            return statusData();
        }else if(dictName.equals(CommonDataUtil.PROCESS)){
            return processData();
        }else if(dictName.equals(CommonDataUtil.PRODUCT_STATUS)){
            return productStatusData();
        }else if(dictName.equals(CommonDataUtil.DISH_FLAVOR)) {
            return dishFlavorData();
        }else{
            return null;
        }
    }

}
